#!/usr/bin/python
# -*- coding: utf-8 -*-

#This file is part of pyLot library.
#
# pyLot is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyLot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pyLot.  If not, see <http://www.gnu.org/licenses/>.

__author__ = u'Pierre Puiseux, Guillaume Baty'
__copyright__ = u"Copyright 2011-2012 (C) andheo, Université de Pau et des Pays de l'Adour"
__credits__ = [u'Pierre Puiseux', u'Guillaume Baty']
__license__ = "GNU Lesser General Public License"

from Qt4 import QtCore, QtGui

from pyLot.core import hardbook, get_data

from _pylot.qtgui.interfaces.widgetinterface import WidgetInterface
from _pylot.qtgui.tools import generate_pyfile_from_uifile

generate_pyfile_from_uifile(__name__,
  src=hardbook(u'uifiles', u'auto_preferences.ui'),
  dest=get_data(__name__, u'_gui_autopreferences.py'))

from _gui_autopreferences import Ui_GuiAutoPrefs
class GuiAutoPrefs(QtGui.QWidget, Ui_GuiAutoPrefs, WidgetInterface):
  def __init__(self, tabs=False, handler=None):
    QtGui.QWidget.__init__(self)
    WidgetInterface.__init__(self, handler)
    self.setupUi(self)
    self._tabs = tabs
    if self._tabs is True :
      self.tab_widgets = QtGui.QTabWidget()
      self.main_layout.addWidget(self.tab_widgets)

  def addPrefWidget(self, widget):
    u"""
    :param widget: a WidgetInterface widget
    """
    self.append(widget)
    if self._tabs is True :
      self.tab_widgets.addTab(widget, widget.windowTitle())
    else :
      self.main_layout.addWidget(widget)

  def _translate(self):
    if self._tabs is True :
      for idx in range(self.tab_widgets.count()) :
        widget = self.tab_widgets.widget(idx)
        self.tab_widgets.setTabText(idx, widget.windowTitle())
    self._setTexts([
      (self, self.handler.alias)
      ])

